﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using BrokerBase.Lib.Policy;

namespace broker.duty.JHRS
{
    class Class2
    {
        public void Calc1(IPolicyPeriodActing ppa, IDutyActing da)
        {
            double deduct = 0f;

            double ffee = 0f;

            int overPeriod = Convert.ToInt32(ppa.SchemePeriodActing.SchemeActing.GetAuxConfigValue("约定缴费期(年)"));

            if (ppa.Period<overPeriod)
            {
                ffee = Convert.ToDouble(ppa.SchemePeriodActing.SchemeActing.GetAuxConfigValue("期交保险费"));

                switch (ppa.Period)
                {
                    case 0:
                        deduct = ffee * 0.5;
                        break;
                    case 1:
                        deduct = ffee * 0.25;
                        break;
                    case 2:
                        deduct = ffee * 0.15;
                        break;
                    case 3:
                    case 4:
                        deduct = ffee * 0.1;
                        break;
                    case 5:
                    case 6:
                    case 7:
                    case 8:
                    case 9:
                        deduct = ffee * 0.05;
                        break;
                    default:
                        deduct = ffee * 0.03;
                        break;
                }
            }

            

            deduct += 60;//保单管理费;

            if (ppa.Period < ppa.PolicyActing.Policy.Fees.Count())
            {
                double d = ppa.PolicyActing.Policy.Fees[ppa.Period];
                if (d <= double.Epsilon)
                {
                    d = (double)ppa.PolicyActing.PeriodActings[ppa.Period - 1].Tag;
                }
                ppa.Tag = d;
                deduct += d;//约定风险金对应的保费

            }

            int r = 0;

            if (ppa.SchemePeriodActing.InsurantStates.Contains("追加费用"))
            {
                r = Convert.ToInt32(ppa.SchemePeriodActing.SchemeActing.GetAuxConfigValue("追加费用"));
            }

            deduct += r * 0.05;//追加的费用的初始费用
            da.Value = ffee + r - deduct;

            if(ppa.Period>0)
            {
                double f = (double)ppa.SchemePeriodActing.SchemeActing.GetAuxConfigValue("分红率(预估)");
                IPolicyPeriodActing pppa = ppa.PolicyActing.PeriodActings[ppa.Period - 1];
                da.Value += pppa.GetDutyTotalValue("个人账户") * f;
            }

            if (ppa.Period > 2 && ppa.Period < overPeriod)
            {
                da.Value += ffee * 0.02;
            }

            ppa.Fee = ffee + r;

            if (ppa.GetDutyTotalValue("个人账户") <= 0)
            {
                ppa.IsCurrentFinish = true;
                da.Description = "个人账户余额不足，合同终止!";
            }

        }

        public void Calc1(IPolicyPeriodActing ppa, IDutyActing da)
        {
            if (ppa.SchemePeriodActing.InsurantStates.Contains("退保"))
            {
                double amt = 0f;
                double val = ppa.GetDutyTotalValue("个人账户");
                switch (ppa.Period)
                {
                    case 0:
                        amt = val * 0.10;
                        break;
                    case 1:
                        amt = val * 0.03;
                        break;
                    default:
                        amt = 0;
                        break;
                        
                }

                da.Value = val - amt;
                ppa.IsCurrentFinish = true;
            }
        }

        public void Calc1(IPolicyPeriodActing ppa, IDutyActing da)
        {
            if (ppa.SchemePeriodActing.InsurantStates.Contains("身故"))
            {
                da.Value = ppa.Amount + ppa.GetDutyTotalValue("个人账户");
                ppa.IsCurrentFinish = true;
            }
        }
    }
}
